package w83b.w83bOperacionesPaso.w83bActas;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;

import w83b.w83bBeans.W83bActasBean;
import w83b.w83bBeans.W83bConveniosBean;
import w83b.w83bBeans.W83bDatosEscrutiniosBean;
import w83b.w83bUtilidadesComunes.W83bClsConstantes;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

// TODO: Auto-generated Javadoc
/**
 * The Class W83bTablaAgrupacionesOP.java.
 *
 * @author Deusto Sistemas
 */
public class W83bAnyadirDelegadoOutOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//Guardamos la accion en el contexto
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		W83bActasBean acta=(W83bActasBean)contexto.get("w83bNuevaActaBean");
		java.util.HashMap lista = ((java.util.HashMap)contexto.get("w83bBuscarCambioEscrutinio"));
		W83bConveniosBean convenio=(W83bConveniosBean)lista.get("W83bConveniosBean");
		W83bDatosEscrutiniosBean escrutinio=(W83bDatosEscrutiniosBean)lista.get("W83bDatosEscrutiniosBean");
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("especial", "N");
		if(convenio.getConvPorEscrut().equalsIgnoreCase("N")){//ES QUE ES POR ESCRUTINIO
			if(acta.getNumActaTerritorio().length()==1){acta.setNumActaTerritorio("0"+acta.getNumActaTerritorio());}
			if(acta.getNumActaTerritorio().equals(W83bClsConstantes.CONSTANTE_ALAVA)){
				if(convenio.getEspEnAlava().equals("S")){
					jsonObject.put("especial", "S");
				}
			}
			else if(acta.getNumActaTerritorio().equals(W83bClsConstantes.CONSTANTE_BIZKAIA)){
				if(convenio.getEspEnBizkaia().equals("S")){
					jsonObject.put("especial", "S");
				}
			}
			else if(acta.getNumActaTerritorio().equals(W83bClsConstantes.CONSTANTE_GIPUZKOA)){
				if(convenio.getEspEnGuip().equals("S")){
					jsonObject.put("especial", "S");
				}
			}
		}
		jsonObject.put("convenioDiferencia", convenio.getConvPorEscrut());
		jsonObject.put("maxDelgados", escrutinio.getElectoresTotalColegioC1());
		
		
		response.setContentType("text/javascript;charset=iso-8859-1");
		response.setHeader("Pragma", "cache");
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "private");
		response.setStatus(HttpServletResponse.SC_OK);
		PrintWriter out = response.getWriter();
		out.print(jsonObject.toString());
		out.flush();
		
		return null;
	}
	


}
